package com.atguigu.mq.route;

import com.atguigu.mq.util.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        //声明队列
        String queue = "route_queue1";
        channel.queueDeclare(queue,true,false,false,null);

        DefaultConsumer defaultConsumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("body1:"+new String(body));

            }
        };

        // 消费者类似一个监听程序,主要是用来监听消息,客户端自动签收
        channel.basicConsume("route_queue1",true,defaultConsumer);

    }
}
